import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout/index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        name: 'home',
        component: () => import('@/views/home/index.vue'),
        meta: {
          title: '首页'
        }
      },
      {
        path: '/user/:id',
        name: 'user',
        component: () => import('@/views/user/index.vue'),
        redirect: 'index',
        meta: {
          title: '个人主页'
        },
        children: [
          {
            path: 'index',
            name: 'userIndex',
            component: () => import('@/views/user/article.vue')
          },
          {
            path: 'draft',
            name: 'userDrafts',
            component: () => import('@/views/user/draft.vue')
          },
          {
            path: 'concern',
            name: 'userConcerns',
            component: () => import('@/views/user/concern.vue')
          },
          {
            path: 'favorites',
            name: 'userFavorites',
            component: () => import('@/views/user/favoritesList.vue')
          },
          {
            path: 'myNav',
            name: 'userMyNav',
            component: () => import('@/views/user/myNav.vue')
          },
          {
            path: 'myNavCategory',
            name: 'userMyNavCategory',
            component: () => import('@/views/user/myNavCategory.vue')
          }
        ]
      },
      {
        path: '/article-detail/:id',
        name: 'articleDetail',
        component: () => import('@/views/articleDetail/index.vue'),
        meta: {
          title: '文章详情'
        }
      },
      {
        path: '/navigation',
        name: 'navigation',
        component: () => import('@/views/navigation/index.vue'),
        meta: {
          title: '导航'
        }
      },
      {
        path: '/blogging',
        name: 'blogging',
        component: () => import('@/views/blogging/index.vue'),
        meta: {
          title: '写博客'
        }
      },
      {
        path: '/chatRoom',
        name: 'chatRoom',
        component: () => import('@/views/chatRoom/index.vue'),
        meta: {
          title: '聊天室'
        }
      },
      {
        path: '/add-article',
        name: 'addArticle',
        component: () => import('@/views/articleDetail/add.vue'),
        meta: {
          title: '写文章',
          roles: ['admin', 'user']
        }
      },
      {
        path: '/edit-article/:id',
        name: 'editArticle',
        component: () => import('@/views/articleDetail/edit.vue'),
        meta: {
          title: '编辑文章',
          roles: ['admin', 'user']
        }
      },
      {
        path: '/navigation-add',
        name: 'navigationAdd',
        component: () => import('@/views/navigation/add.vue'),
        meta: {
          title: '添加导航',
          roles: ['admin']
        }
      },
      {
        path: '/navigation-edit/:id',
        name: 'navigationEdit',
        component: () => import('@/views/navigation/edit.vue'),
        meta: {
          title: '编辑导航',
          roles: ['admin']
        }
      },
      {
        path: '/search',
        name: 'search',
        component: () => import('@/views/search/index.vue'),
        meta: {
          title: '搜索'
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true }
]

const router = new VueRouter({
  mode: 'history',
  base: '/',
  routes
})

export default router
